package com.boyunv.strategy.example03;
/*
 *@description
 *
 *@author boyunv
 *@create 2023/8/15 7:44
 *@version 1.0
 */

import com.boyunv.strategy.example02.Receipt;
import com.boyunv.strategy.example02.ReceiptBuilder;

import java.util.List;

public class Client {
    public static void main(String[] args) {
        //模拟回执
        List<Receipt> receiptList= ReceiptBuilder.getReceiptList();
        
        //策略上下文
        ReceiptStrategyContext context = new ReceiptStrategyContext();
        for (Receipt receipt : receiptList) {
            //获取策略
            ReceiptHandleStrategyFactory.init();
            ReceiptHandlerStrategy strategy = ReceiptHandleStrategyFactory.getStrategy(receipt.getType());
            //设置策略
            context.setReceiptHandlerStrategy(strategy);
            //执行策略
            context.handleReceipt(receipt);
            
        }
    }
}
